<template>

    <div class="login" >
        <el-form ref="loginForm" class="login-form">
            <h3 class="title">智慧社区管理系统</h3>
            <el-form-item prop="username">
                <el-input
                        v-model="username"
                        type="text"
                        auto-complete="off"
                        placeholder="账号"
                >
                    <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
                </el-input>
            </el-form-item>
            <el-form-item prop="password">
                <el-input
                        v-model="password"
                        type="password"
                        auto-complete="off"
                        placeholder="密码"
                        @keyup.enter.native="handleLogin"
                >
                    <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
                </el-input>
            </el-form-item>
            <el-form-item style="width:100%;">
                <el-button
                        size="medium"
                        type="primary"
                        style="width:100%;"
                        @click.native.prevent="handleLogin"
                >
                    登录
                </el-button>
            </el-form-item>
        </el-form>
    </div>

<!--    <div>-->
<!--        <span>{{msg}}</span>-->
<!--        <el-input v-model="username"></el-input><br>-->
<!--        <el-input v-model="password" type="password"></el-input><br>-->
<!--        <el-button type="primary" @click="handleLogin">登录</el-button>-->
<!--    </div>-->
</template>

<script>
    export default {
        name: "Login",
        data(){
            return{
                username:"",
                password:"",
                msg:""
            }
        },
        methods:{
            handleLogin(){
                this.axios.post("http://localhost:8080/login",
                    this.qs.stringify({"username":this.username,"password":this.password}))
                    .then(res => {
                        if(res.data.status == "OK"){
                            //如果登录成功，就获得token,保存到本地
                            localStorage.setItem("username",res.data.data.username);
                            localStorage.setItem("token",res.data.data.token);
                            //跳转到user页面
                            this.$router.push({path:"/index"});
                        }else{
                            this.msg = "账号或密码错误";
                        }
                    });
            }
        }
    }
</script>

<style scoped>


    .login {
        display: flex;
        justify-content: center;
        align-items: center;
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        background-image: url("../assets/images/loginbackground.jpg");
        background-size: cover;
    }
    .title {
        margin: 0px auto 30px auto;
        text-align: center;
        color: #707070;
    }

    .login-form {
        border-radius: 6px;
        background: #ffffff;
        width: 400px;
        padding: 25px 25px 5px 25px;
        position: absolute;
        top: 150px;
    }
    .el-input {
        height: 38px;
    }
    input {
        height: 38px;
    }
    .input-icon {
        height: 39px;
        width: 14px;
        margin-left: 2px;
    }
    .login-tip {
        font-size: 13px;
        text-align: center;
        color: #bfbfbf;
    }
    .login-code {
        width: 33%;
        height: 38px;
        float: right;
    }
    img {
        cursor: pointer;
        vertical-align: middle;
    }
    .el-login-footer {
        height: 40px;
        line-height: 40px;
        position: fixed;
        bottom: 0;
        width: 100%;
        text-align: center;
        color: #fff;
        font-family: Arial;
        font-size: 12px;
        letter-spacing: 1px;
    }
    .login-code-img {
        height: 38px;
    }



</style>
